import { type Ref, ref, computed, h, Fragment } from "vue";
import type { PlusColumn, FieldValues, OptionsRow } from "plus-pro-components";
import { ElUpload, ElButton } from "element-plus";
import { getToken, formatToken } from "@/utils/auth";
import { message } from "@/utils/message";
import { getIssues } from "@/api/zhaoyuan";
const { token } = getToken();
export function useForm(pageEnums: Ref<{ [key: string]: OptionsRow[] }>) {
  const formRules = {
    name: [
      {
        required: true,
        message: "请输入名称"
      }
    ]
  };
  const formColumns: PlusColumn[] = [
    {
      label: "标题",
      prop: "title"
    },
    {
      label: "描述",
      prop: "description",
      valueType: "textarea",
      fieldProps: {
        maxlength: 2500,
        showWordLimit: true,
        autosize: { minRows: 3, maxRows: 10 }
      }
    },
    {
      label: "分类",
      prop: "category"
    },
    {
      label: "提交者ID",
      prop: "submitterId"
    },
    {
      label: "提交者姓名",
      prop: "submitterName"
    }
  ];
  const formTitle = ref("");
  const formId = ref<number>(0);
  const formVisible = ref(false);
  const formValues = ref<FieldValues>({});
  const formOpen = async (title = "新增", row: any = {}) => {
    //重置表单
    if (title == "修改") {
      formId.value = row.id;
      const res = await getIssues(row.id);
      formValues.value = res;
    } else {
      formId.value = 0;
      formValues.value = {};
    }
    formTitle.value = title;
    formVisible.value = true;
  };
  return {
    formRules,
    formColumns,
    formVisible,
    formValues,
    formOpen,
    formTitle,
    formId
  };
}
